package com.yanqu.road.server.cmd.strongholdwar;

import com.yanqu.road.pb.activity.StrongholdWarProto;
import com.yanqu.road.pb.rank.RankProto;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.ActivityMgr;
import com.yanqu.road.server.manager.strongholdwar.CrossStrongholdRankMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_CROSS_STRONGHOLD_USER_RANK, desc = "")
public class CrossStrongholdUserRankCmd extends CrossUnionCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        long userId = packet.getPlayerId();
        StrongholdWarProto.StrongholdActivityUserRankListReqMsg req = StrongholdWarProto.StrongholdActivityUserRankListReqMsg.parseFrom(packet.getBytes());
        int conditionType = req.getConditionType();
        int activityId = req.getActivityId();
        int rank = CrossStrongholdRankMgr.getCrossActivityRank(activityId, conditionType, serverId, userId);
        StrongholdWarProto.StrongholdActivityUserRankListRespMsg.Builder resp = StrongholdWarProto.StrongholdActivityUserRankListRespMsg.newBuilder();
        RankProto.RankListMsg.Builder rankListMsg = CrossStrongholdRankMgr.getCrossActivityRankListModel(activityId, groupId, conditionType, true).getRankListMsg();
        resp.setMyRank(rank);
        RankProto.RankListMsg.Builder tempMsg = RankProto.RankListMsg.newBuilder();
        int num = 0;
        for (RankProto.RankTempMsg msg : rankListMsg.getRankListList()) {
            tempMsg.addRankList(msg);
            num++;
            if (num >= ActivityMgr.getRankListShowNum()) {
                break;
            }
        }
        resp.setRankList(tempMsg);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(ClientProtocol.U_STRONGHOLD_USER_RANK, resp);
        MessageHelper.sendPacket(serverId, userId, pbMsg);
    }

    @Override
    public void sendData() {

    }
}
